<template>
  <div class="centreLeft1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span>
          <i class="iconfont icon-tongji4" />
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">任务通过率</span>
          <dv-decoration-3 class="dv-dec-3" />
        </div>
      </div>
      <div class="d-flex jc-center">
        <!-- <chart /> -->
        <!-- <div id="myEcharts" style="width: 100%; height: 360px;"
  									v-bind:key="cdata.seriesData[0][0]"></div> -->
        <div id="myEcharts" style="width: 100%; height: 360px;"></div>
      </div>
      <!-- 4个主要的数据 -->
      <div class="bottom-data">
        <div
          class="item-box mt-2"
          v-for="(item, index) in numberData"
          :key="index"
        >
          <div class="d-flex jc-end">
            <i class="iconfont" :class="[iconFont[index]]" />
            <dv-digital-flop class="dv-digital-flop" :config="item.config" />
          </div>
          <p>
            <span> {{ item.text }} </span>
            <span class="colorYellow">(件)</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts';
import { defineComponent, inject, onMounted, onUnmounted,  reactive , ref } from 'vue'
//1、声明定义一个echarts
let echart = echarts
//2、基础配置
const cdata = reactive({
   xData: [''],
  seriesData: [
    { value: 10, name: '数据1' },
    { value: 5, name: '数据2' },
    { value: 15, name: '数据3' },
    { value: 25, name: '数据4' },
    { value: 20, name: '数据5' },
    { value: 35, name: '数据6' },
  ],
})

const initChart = (data: any) => {
  let chart = echart.init(document.getElementById("myEcharts"));
  chart.setOption({
    // 这里面的数据在 drawt.tsx 复制的
    color: [
      '#37a2da',
      '#32c5e9',
      '#9fe6b8',
      '#ffdb5c',
      '#ff9f7f',
      '#fb7293',
      '#e7bcf3',
      '#8378ea'
    ],
    tooltip: {
      trigger: 'item',
      formatter: '{a} <br/>{b} : {c} ({d}%)'
    },
    toolbox: {
      show: true
    },
    calculable: true,
    legend: {
      orient: 'horizontal',
      icon: 'circle',

      bottom: 0,
      x: 'center',
      data: cdata.seriesData,
      textStyle: {
        color: '#fff'
      }
    },
    series: [
      {
        name: '销量总占比',
        type: 'pie',
        radius: [20, 80],
        roseType: 'area',
        center: ['50%', '40%'],
        itemStyle: {
          borderRadius: 5
        },
        label: {
          show: true,
          color: "#fff",
        },
        emphasis: {
          label: {
            show: false
          }
        },
        data: cdata.seriesData
      }
    ]

  })
}

//axios的传入
const $axios = inject("$axios")

const result=ref([])
const getCarData = async () => { 
  const res = await $axios.get("myApp/centerLeft/")
  cdata.seriesData = res.data.lastPieList
  initChart(res)
  console.log(cdata.seriesData);
  
}


    // 下层数据
    const dataArr = [
      {
        number: 150,
        text: '今日构建总量'
      },
      {
        number: 144,
        text: '总共完成数量'
      },
      {
        number: 361,
        text: '正在编译数量'
      },
      {
        number: 571,
        text: '未通过数量'
      }
    ]
    // 对应图标
    const iconFont = [
      'icon-diagnose',
      'icon-monitoring',
      'icon-cloudupload',
      'icon-clouddownload'
    ]
    const numberData = reactive([])
    let intervalInstance = null
onMounted(() => {
    getCarData()  
      // setData()
      // changeTiming()
    })

    

    const changeTiming = () => {
      intervalInstance = setInterval(() => {
        changeNumber()
      }, 2000)
    }
    const changeNumber = () => {
      numberData.forEach((item, index) => {
        item.config.number[0] += ++index
        item.config = { ...item.config }
      })
    }
    onUnmounted(() => {
      clearInterval(intervalInstance)   
    })

</script>

<style lang="scss" scoped>
$box-width: 300px;
$box-height: 410px;

.centreLeft1 {
  padding: 16px;
  height: $box-height;
  width: $box-width;
  border-radius: 10px;
  .bg-color-black {
    height: $box-height - 30px;
    border-radius: 10px;
  }
  .text {
    color: #c3cbde;
  }
  .dv-dec-3 {
    position: relative;
    width: 100px;
    height: 20px;
    top: -3px;
  }

  .bottom-data {
    .item-box {
      & > div {
        padding-right: 5px;
      }
      font-size: 14px;
      float: right;
      position: relative;
      width: 50%;
      color: #d3d6dd;
      .dv-digital-flop {
        width: 120px;
        height: 30px;
      }
      i {
        font-size: 20px;
        line-height: 30px;
        margin-left: 20px;
      }
      .colorYellow {
        color: yellowgreen;
      }
      p {
        text-align: center;
      }
    }
  }
}
</style>
